<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.example.model.Post" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background-color: #f5f5f5;
            padding: 20px;
        }
        
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #ddd;
        }
        
        .page-title {
            font-size: 24px;
            font-weight: bold;
            color: #333;
        }
        
        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .new-post-btn {
            padding: 8px 15px;
            background-color: #4a90e2;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s;
            text-decoration: none;
            display: inline-block;
            margin-bottom: 20px;
        }
        
        .new-post-btn:hover {
            background-color: #3a7bc8;
        }
        
        .welcome-text {
            color: #666;
        }
        
        .logout-btn {
            color: #4a90e2;
            text-decoration: none;
            font-size: 14px;
            transition: color 0.3s;
        }
        
        .logout-btn:hover {
            color: #3a7bc8;
            text-decoration: underline;
        }
        
        .blog-list {
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }
        
        .post {
            border-bottom: 1px solid #eee;
            padding: 15px 0;
            margin-bottom: 10px;
        }
        
        .post:last-child {
            border-bottom: none;
        }
        
        .post h2 {
            color: #333;
            margin-bottom: 10px;
        }
        
        .post p {
            color: #666;
            margin-bottom: 10px;
        }
        
        .post-actions {
            margin-top: 10px;
            display: flex;
            gap: 10px;
            align-items: center;
        }
        
        .edit-btn {
            color: #4a90e2;
            text-decoration: none;
        }
        
        .edit-btn:hover {
            text-decoration: underline;
        }
        
        .delete-btn {
            padding: 4px 8px;
            background-color: #ff4d4d;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 12px;
        }
        
        .delete-btn:hover {
            background-color: #e60000;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1 class="page-title">博客列表</h1>
        <div class="user-info">
            <span class="welcome-text">欢迎，${sessionScope.user.username}</span>
            <a href="${pageContext.request.contextPath}/auth/logout" class="logout-btn">登出</a>
        </div>
    </div>
    
    <a href="${pageContext.request.contextPath}/posts/new" class="new-post-btn">写新博客</a>
    
    <div class="blog-list">
        <% for (Post post : (List<Post>)request.getAttribute("posts")) { %>
            <div class="post">
                <h2><%= post.getTitle() %></h2>
                <p><%= post.getContent() %></p>
                <p>发布时间: <%= post.getCreatedAt() %></p>
                <div class="post-actions">
                    <a href="${pageContext.request.contextPath}/posts/edit?id=<%= post.getId() %>" class="edit-btn">编辑</a>
                    <form style="display: inline;" method="post" action="${pageContext.request.contextPath}/posts">
                        <input type="hidden" name="action" value="delete">
                        <input type="hidden" name="id" value="<%= post.getId() %>">
                        <input type="submit" value="删除" class="delete-btn" onclick="return confirm('确定要删除吗？')">
                    </form>
                </div>
            </div>
        <% } %>
    </div>
</body>
</html> 